<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTorneosUsuariosTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		//
		Schema::create('torneos_usuarios', function($table)
		{
			$table->string('equipo');
			$table->integer('puntuacion');
			$table->integer("user_id")->unsigned();
			$table->foreign("user_id")->references('id')->on('users')->onDelete('cascade');
			$table->integer("torneo_id")->unsigned();
			$table->foreign("torneo_id")->references('id')->on('torneos')->onDelete('cascade');
			$table->timestamps();
			$table->primary(array('user_id','torneo_id'));
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('torneos_usuarios', function($table)
		{
			$table->dropForeign('torneos_usuarios_user_id_foreign');
			$table->dropForeign('torneos_usuarios_torneo_id_foreign');
		});
		
		Schema::dropIfExists('torneos_usuarios');
	}

}
